package com.ruoyi.order.controller;

import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.order.domain.UserCoupon;
import com.ruoyi.order.service.IUserCouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 优惠券中间Controller
 * 
 * @author jsj
 * @date 2024-03-27
 */
@RestController
@RequestMapping("/userCoupon")
public class UserCouponController extends BaseController
{
    @Autowired
    private IUserCouponService userCouponService;

    /**
     * 查询优惠券中间列表
     */
    @RequiresPermissions("order:userCoupon:list")
    @GetMapping("/list")
    public TableDataInfo list(UserCoupon userCoupon)
    {
        startPage();
        List<UserCoupon> list = userCouponService.list();
        return getDataTable(list);
    }

//    /**
//     * 导出优惠券中间列表
//     */
//    @RequiresPermissions("order:userCoupon:export")
//    @Log(title = "优惠券中间", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, UserCoupon userCoupon)
//    {
//        List<UserCoupon> list = userCouponService.selectUserCouponList(userCoupon);
//        ExcelUtil<UserCoupon> util = new ExcelUtil<UserCoupon>(UserCoupon.class);
//        util.exportExcel(response, list, "优惠券中间数据");
//    }

    /**
     * 获取优惠券中间详细信息
     */
    @RequiresPermissions("order:userCoupon:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(userCouponService.getById(id));
    }

    /**
     * 新增优惠券中间
     */
    @RequiresPermissions("order:userCoupon:add")
    @Log(title = "优惠券中间", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserCoupon userCoupon)
    {
        return toAjax(userCouponService.save(userCoupon));
    }

    /**
     * 修改优惠券中间
     */
    @RequiresPermissions("order:userCoupon:edit")
    @Log(title = "优惠券中间", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserCoupon userCoupon)
    {
        return toAjax(userCouponService.updateById(userCoupon));
    }

    /**
     * 删除优惠券中间
     */
    @RequiresPermissions("order:userCoupon:remove")
    @Log(title = "优惠券中间", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(userCouponService.removeByIds(Arrays.asList(ids)));
    }



}
